package br.uninove.jimage.view;

import java.awt.BorderLayout;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import br.uninove.jimage.view.components.filechooser.FileChooserImage;
import java.awt.Dimension;

public class ImageToCassification extends JDialog {

	private static final long serialVersionUID = 1L;
	private JPanel panelPrincipal = null;
	private JLabel lblMsg = null;
	private JTextField txtPathImage = null;
	private JButton btnAbrir = null;
	private JButton btnFechar = null;
	private ClassificarView classificarView;


	public ImageToCassification( ClassificarView classificarView ) {
		super( );
		initialize( );
		this.classificarView = classificarView;
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(477, 139);
		this.setContentPane(getPanelPrincipal());
		this.setLocationRelativeTo(null);
	}

	/**
	 * This method initializes panelPrincipal
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getPanelPrincipal() {
		if (panelPrincipal == null) {
			BorderLayout borderLayout = new BorderLayout();
			borderLayout.setHgap(10);
			borderLayout.setVgap(10);
			lblMsg = new JLabel();
			lblMsg.setText("Favor, entrar com a imagen que deseja classificar:");
			panelPrincipal = new JPanel();
			panelPrincipal.setLayout(borderLayout);
			panelPrincipal.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
			panelPrincipal.add(lblMsg, BorderLayout.NORTH);
			panelPrincipal.add(getTxtPathImage(), BorderLayout.CENTER);
			panelPrincipal.add(getBtnAbrir(), BorderLayout.EAST);
			panelPrincipal.add(getBtnFechar(), BorderLayout.SOUTH);
		}
		return panelPrincipal;
	}

	/**
	 * This method initializes txtPathImage	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getTxtPathImage() {
		if (txtPathImage == null) {
			txtPathImage = new JTextField();
		}
		return txtPathImage;
	}

	/**
	 * This method initializes btnAbrir	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnAbrir() {
		if (btnAbrir == null) {
			btnAbrir = new JButton();
			btnAbrir.setText("Abrir");
			btnAbrir.addActionListener( new java.awt.event.ActionListener( ) {
				public void actionPerformed( java.awt.event.ActionEvent e ) {
					FileChooserImage chooserImage = new FileChooserImage( );
					txtPathImage.setText( chooserImage.abrirImagem( ) );
				}
			} );
		}
		return btnAbrir;
	}

	/**
	 * This method initializes btnFechar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnFechar( ) {
		if (btnFechar == null) {
			btnFechar = new JButton( );
			btnFechar.setText("Fechar");
			btnFechar.addActionListener( new java.awt.event.ActionListener( ) {
				public void actionPerformed( java.awt.event.ActionEvent e ) {
					fecharDialog();
				}
			} );
		}
		return btnFechar;
	}
	
	

	private void fecharDialog( ) {
		classificarView.setImagePraClassificar( txtPathImage.getText( ) );
		classificarView.initialize( );
		classificarView.getTela( ).mostraImagem(classificarView);
		this.dispose( );
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"
